home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 1992 August / info-mac-1992.iso / Applications (app) / Image 1.44 / Macros / More Macros < prev    next >
Text File  |  1992-03-20  |  9KB  |  427 lines

  1. macro 'Invert Image';
  2. {
  3. This macro illustrates why it's not a good idea to use
  4. macros to do pixel-by-pixel processing.
  5. }
  6. var
  7.   width,height,value,x,y:integer;
  8. begin
  9.   RequiredVersion(1.44);
  10.   GetPicSize(width,height);
  11.   for y:=0 to height-1 do begin
  12.     GetRow(0,y,width);
  13.     for x:=0 to width-1 do LineBuffer[x]:=255-LineBuffer[x];
  14.     PutRow(0,y,width);
  15.   end;
  16. end;
  17.  
  18.  
  19. macro 'Remove Isolated Black Lines';
  20. var
  21.   width,height,value,x,y,xstart,ystart:integer;
  22. begin
  23.   GetRoi(xstart,ystart,width,height);
  24.   if width=0 then begin
  25.     PutMessage('This macro requires a retangular selection');
  26.     exit;
  27.   end;
  28.   for y:=ystart to ystart+height-1 do begin
  29.     if GetPixel(width div 2,y)=255 then
  30.       for x:=xstart to xstart+width-1 do
  31.         PutPixel(x,y,(GetPixel(x,y-1)+GetPixel(x,y+1))/2);
  32.   end;
  33.   KillRoi;
  34. end;
  35.  
  36.  
  37. macro 'Make Mosaic';
  38. var
  39.   n:integer;
  40. begin
  41.   SaveState
  42.   n:=GetNumber('Cell Size(pixels square):',8);
  43.   Duplicate('Mosaic');
  44.   SetScaling('Nearest; Same Window');
  45.   ScaleSelection(1/n,1/n);
  46.   RestoreRoi;
  47.   ScaleSelection(n,n);
  48.   RestoreState;
  49. end;
  50.  
  51.  
  52. macro 'Draw Vertical Scale with Labels';
  53. var
  54.   left,top,width,height,i,x,y2,inc:integer;
  55.   y:real;
  56. begin
  57.   GetRoi(left,top,width,height);
  58.   if width=0 then begin
  59.     PutMessage('Make a selection first.');
  60.     exit;
  61.   end;
  62.   SetFont('Helvetica');
  63.   SetFontSize(10);
  64.   SetText('Plain; Left; no background');
  65.   SetLineWidth(1);
  66.   Setforeground(255);
  67.   DrawScale;
  68.   x:=left;
  69.   y:=top;
  70.   inc:=height/10;
  71.   for i:=1 to 11 do begin
  72.     MoveTo(x+width+10,round(y)+2);
  73.     y2:=round(y);
  74.     if i=11 then y2:=y2-1;
  75.     write(cvalue(GetPixel(x,y2)):1:2);
  76.     y:=y+inc;
  77.   end;
  78. end;
  79.  
  80.  
  81. macro 'Speckle Paint [S]';
  82. var
  83.   x,y,ranx,rany,MaxSpeckSize,size,Spread:integer;
  84. begin
  85.   {SaveState;}
  86.   Spread:=50;
  87.   MaxSpeckSize:=5;
  88.   KillRoi;
  89.   repeat
  90.     GetMouse(x,y);
  91.     if button then begin
  92.       ranx:=x+Spread*(Random-0.5);
  93.       rany:=y+Spread*(Random-0.5);
  94.       size:=(MaxSpeckSize-2)*random+2;
  95.       MakeOvalRoi(ranx-size,rany-size,size*2,size*2);
  96.       SetForeground(Random*254+1)
  97.       fill;
  98.     end;
  99.   until (x<0) or (y<0);
  100.   KillRoi;
  101.   {RestoreState;}
  102. end;
  103.  
  104.  
  105. macro 'Draw Histogram';
  106. var
  107.   max,scale:real;
  108.   i,margin,width,height:integer;
  109. begin
  110.   SaveState;
  111.   Margin:=10;
  112.   width:=256;
  113.   height:=0.6*256;
  114.   Measure;
  115.   SetForegroundColor(255);
  116.   SetBackgroundColor(0);
  117.   SetLineWidth(1);
  118.   SetNewSize(width+2*margin,height+2*margin);
  119.   MakeNewWindow('Histogram');
  120.   MakeRoi(margin,margin-1,width,height+1);
  121.   DrawBoundary;
  122.   max:=0;
  123.   for i:=1 to 254 do
  124.   if histogram[i]> max then max:=histogram[i];
  125.   scale:=height/max;
  126.   for i:=1 to 254 do begin
  127.     MakeRoi(margin+i,margin,1,histogram[i]*scale);
  128.     SetForegroundColor(i);
  129.     fill;
  130.  end;
  131.   SelectAll;
  132.   FlipVertical;
  133.   KillRoi;
  134.   RestoreState;
  135. end;
  136.  
  137.  
  138. macro 'Subtract Background';
  139. var
  140.   i,Corrected,smoothf:integer;
  141.   scalef:real;
  142. begin
  143.   scalef:=1;
  144.   smoothf:=150;
  145.   SelectAll;
  146.   Duplicate('Background Corrected');
  147.   Corrected:=PicNumber;
  148.   Duplicate('Background'); 
  149.   ScaleSelection(scalef,scalef);
  150.   RestoreRoi;
  151.   for i:=1 to smoothf do begin
  152.     SetOption; Smooth;
  153.   end;
  154.   ScaleSelection(1/scalef,1/scalef);
  155.   SelectAll;
  156.   Copy;
  157.   SelectPic(Corrected);
  158.   Paste;
  159.   Subtract;
  160.   ResetGrayMap;
  161. end;
  162.  
  163.  
  164. macro 'ASCII Dump';
  165. {
  166. Generates an alphanumeric listing of pixels values starting at
  167. the upper left corner of the current selection. 20 rows and 44 columns
  168. can be displayed with the default 552 x 436 window. The size of the window
  169. used to display the pixel values is determined by New Width and
  170. New Height in the Prefernces dialog box.
  171. }
  172. var
  173.   image,dump,roiLeft,roiTop,roiWidth,roiHeight:integer;
  174.   h,v,value,MaxWidth,MaxHeight,width,height:integer;
  175. begin
  176.   image:=PicNumber;
  177.   GetRoi(RoiLeft,RoiTop,RoiWidth,RoiHeight);
  178.   if roiWidth=0 then begin
  179.     PutMessage('This macro requires a rectangular selection');
  180.     exit;
  181.   end;
  182.   SetForegroundColor(255);
  183.   SetBackgroundColor(0);
  184.   MakeNewWindow('ASCII Dump');
  185.   dump:=PicNumber;
  186.   GetPicSize(width,height);
  187.   MaxWidth:=width div 24 - 2;
  188.   MaxHeight:=height div 9 - 3;
  189.   if roiWidth>MaxWidth then roiWidth:=MaxWidth;
  190.   if roiHeight>MaxHeight then roiHeight:=MaxHeight;
  191.   SetFont('Monaco');
  192.   SetFontSize(9);
  193.   SetText('No background; Left Justified');
  194.   MoveTo(2,12);
  195.   write('    ');
  196.   for h:=roiLeft to roiLeft+roiWidth-1 do write(h:4);
  197.   writeln;
  198.   writeln;
  199.   for v:=roiTop to roiTop+roiHeight-1 do begin
  200.     write(v:3,' ');
  201.     for h:=roiLeft to roiLeft+roiWidth-1 do begin
  202.       ChoosePic(image);
  203.       value:=GetPixel(h,v);
  204.       ChoosePic(dump);
  205.       write(value:4);
  206.     end;
  207.     writeln;
  208.   end;
  209.   ChoosePic(image);
  210. end;
  211.  
  212.  
  213. macro 'Resize All';
  214. {
  215. Resizes and/or rotates all currently open widows. For example,
  216. change the  ScaleAndRotate command below to
  217. ScaleAndRotate(2,2,0)  to change the size of all the images
  218. in a movie loop sequence from 128 x 128 to 256 x 256.
  219. }
  220. var
  221.   i:integer;
  222. begin
  223.   SaveState;
  224.   SetScaling('Bilinear; Create New Window');
  225.   for i:=1 to nPics do begin
  226.     ChoosePic(1);
  227.     ScaleAndRotate(1.9,1.9,0);
  228.     ChoosePic(1);
  229.     Close;
  230.   end;
  231.   for i:=1 to nPics do begin
  232.     ChoosePic(i);
  233.     SetPicName(i);
  234.   end;
  235.   RestoreState;
  236. end;
  237.  
  238.  
  239. macro 'Dispose All';
  240. begin
  241.   DisposeAll;
  242. end;
  243.  
  244. macro 'Average two Images';
  245.   {Generates the arithmetic average of two images.}
  246. begin
  247.   if nPics<>2 then begin
  248.     PutMessage('This macro requires exactly two image windows to be open.');
  249.     Exit;
  250.   End;
  251.   ScaleMath(false);
  252.   MultiplyByConstant(0.5);
  253.   NextWindow;
  254.   MultiplyByConstant(0.5);
  255.   SelectAll;
  256.   Copy;
  257.   NextWindow;
  258.   Paste;
  259.   Add;
  260. end;
  261.  
  262.  
  263. macro 'Make Montage [M]';
  264. {Opens a new window and creates in it a composite image made from all}
  265. {currently open images. All the images must be the same size.}
  266. var
  267.   width,height,w,h,mWidth,mHeight,nWindows,left,top:integer;
  268.   RoiWidth,RoiHeight,RoiWidth,RoiHeight,i,hloc,vloc:integer;
  269.   montage,temp:integer;
  270.   scale:real;
  271.   SameSize:boolean;
  272. begin
  273.   nWindows:=nPics;
  274.   SameSize:=true;
  275.   GetPicSize(width,height);
  276.   for i:=1 to nPics do begin
  277.     SelectPic(i);
  278.     GetPicSize(w,h);
  279.     SameSize:=SameSize and (w=width) and (h=height);
  280.   end;
  281.   if (nWindows<2) or not SameSize then begin
  282.     PutMessage('This macro needs two or more images of the same size in order to create a montage.');
  283.     Exit;
  284.   end;
  285.   SetBackground(0);
  286.   MakeNewWindow('Montage');
  287.   montage:=nWindows+1;
  288.   GetPicSize(mWidth,mHeight);
  289.   SelectPic(1);
  290.   Duplicate('Temp');
  291.   temp:=nWindows+2;
  292.   scale:=GetNumber('Scaling Factor:',0.25);
  293.   hloc:=-(RoiWidth);
  294.   vloc:=0;
  295.   for i:=1 to nWindows do begin
  296.     SelectPic(i);
  297.     SelectAll;
  298.     copy;
  299.     SelectPic(temp);
  300.     paste;
  301.     SelectAll;
  302.     ScaleSelection(scale,scale);
  303.     RestoreRoi;
  304.     if i=1 then begin
  305.       GetRoi(left,top,RoiWidth,RoiHeight);
  306.       hloc:=-RoiWidth;
  307.       vloc:=0;
  308.     end;
  309.     Copy;
  310.     SelectPic(montage);
  311.     hloc:=hloc+RoiWidth;
  312.     if (hloc+RoiWidth)>mWidth then begin
  313.       hloc:=0;
  314.       vloc:=vloc+RoiHeight;
  315.     end;
  316.     MakeRoi(hloc,vloc,RoiWidth,RoiHeight);
  317.     Paste;
  318.   end;
  319.   KillRoi;
  320.   SelectPic(temp);
  321.   Dispose;
  322. end;
  323.  
  324.  
  325. macro 'Make Sine Wave';
  326. var
  327.   left,top,width,height,i:integer;
  328.   ppp,scale:real;
  329. begin
  330.   SaveState;
  331.   MakeNewWindow('Sine Wave');
  332.   SelectAll;
  333.   GetRoi(left,top,Width,Height);
  334.   if width=0 then begin
  335.     PutMessage('This macro requires a rectangular selection.');
  336.     Exit;
  337.   end;
  338.   ppp:=GetNumber('Pixels per period',100);
  339.   Scale:=ppp/6.28;
  340.   MakeRoi(left,top,1,height);
  341.   for i:=1 to width do begin
  342.     SetForeground(sin(i/scale)*127 +128);}
  343.     {SetForeground((sin(i/scale)*127 +128)*(i+30)/(width));
  344.     {SetForeground(sin(i/(ppp*((width-i+3)/width)/6.28))*127 +128);}
  345.     fill;
  346.     MoveRoi(1,0);
  347.   end;
  348.   KillRoi;
  349.   RestoreState;
  350. end;`
  351.  
  352.  
  353. macro 'Grid';
  354. var
  355.   n,PicWidth,PicHeight,hloc,vloc,size:integer;
  356. begin
  357.   SaveState;
  358.   n:=24;
  359.   GetPicSize(PicWidth,PicHeight);
  360.   if PicWidth=0 then begin
  361.     PutMessage
  362.     ('This macro needs an opened image, preferably in color, to operate on.');
  363.     Exit;
  364.   end;
  365.   size:=round(PicWidth/n);
  366.   repeat
  367.     hloc:=((PicWidth*random) div size)*size;
  368.     vloc:=((PicHeight*random) div size)*size;
  369.     MakeRoi(hloc,vloc,size,size);
  370.     SetForeground(255*random);
  371.     fill;
  372.     {Invert;}
  373.   until Button;
  374.   KillRoi;
  375.   RestoreState;
  376. end;
  377.  
  378.  
  379. macro 'Plot XYZ';
  380. {
  381. Plots X-Y coordinate points with an optional intensity(Z). Values are read from
  382. a 2 or 3 column tab-delimited text file. Data must be scaled as follows:
  383. 0<=X<width; 0<=Y<height; 0<=Z<=255.
  384. }
  385. var
  386.   width,height:integer;
  387. begin
  388.   width:=450;
  389.   height:=500;
  390.   SetNewSize(width,height);
  391.   MakeNewWindow('Plot');
  392.   PlotXYZ;
  393. end;
  394.  
  395.  
  396. macro '(---'; begin end;
  397.  
  398. macro '5x5 [5]';
  399. {
  400. Note: you only see the open file dialog box the first time one of
  401. these macros is called, since Image keeps track of the folder
  402. containing the convolution kernels.
  403. }
  404. begin
  405.   convolve('Hat(5x5)');
  406. end;
  407.  
  408. macro '7x7  [7]'
  409. begin
  410.   convolve('Hat(7x7)');
  411. end;
  412.  
  413. macro '9x9  [9]'
  414. begin
  415.   convolve('Hat(9x9)');
  416. end;
  417.  
  418.  
  419. macro '(---'; begin end;
  420.  
  421. {These macros allow you to easily switch}
  422. {transfer modes while pasting by tapping keys.}
  423. macro 'Copy Mode[F1]'; begin SetOption; DoCopy; end;
  424. macro 'AND Mode[F2]';  begin SetOption; DoAnd; end;
  425. macro 'OR Mode [F3]';  begin SetOption; DoOr; end;
  426.  
  427.